import React from 'react';
import { LegionsProModal,LegionsStore } from 'legions-pro-design'
import { OpenConfirm } from 'legions-lunar/antd-toolkit';
import { Button,message } from 'antd';
import ProjectQueryPropertyStore from '../../stores/projectQueryProperty';
import TableOperationProerty from '../components.property/tableOperationProperty';
import ProjectStore from '../../stores/projectStore';
import { PropertyTableOperationFormFields } from '../../models/form/propertyFormModel';
/** 操作区域组件属性设置对话框组件 */
export const OperationAreaPropertyModal = () => {
    const store = LegionsStore.get(ProjectStore);
    return <LegionsProModal
        onOk={() => {
            store.formProperyOperattionRef && store.formProperyOperattionRef.viewModel.form.validateFields((err,values: PropertyTableOperationFormFields) => {
                const value = PropertyTableOperationFormFields.formFieldsToData(PropertyTableOperationFormFields,store.formProperyOperattionRef.viewModel.InputDataModel)
                const TablePropertyApp = store.context.listPagePropertyApp.context.TablePropertyApp;
                if (!err) {
                    const _index = TablePropertyApp.viewModel.operationConfigCode.findIndex(item => item.id === TablePropertyApp.viewModel.openOperationConfigId)
                    if (_index > -1) {
                        TablePropertyApp.viewModel.dispatchAction(() => {
                            TablePropertyApp.viewModel.operationConfigCode[_index] = {
                                ...TablePropertyApp.viewModel.operationConfigCode[_index],
                                ...{
                                    name: value['name'],nameEn: value['nameEn'],apiUrl: value['apiUrl'],
                                    method: value['method'],
                                },
                            }
                            TablePropertyApp.viewModel.operationConfigCode = TablePropertyApp.viewModel.operationConfigCode.slice()
                        })
                        message.success('属性设置成功');
                        TablePropertyApp.operationModalRef.viewModel.visible = false;
                    }
                } else {
                    console.log(value)
                }
                console.log(TablePropertyApp.viewModel.operationConfigCode)
            })
        }}
        modalType="drawer"
        placement="right"
        onReady={(value) => {
            store.context.listPagePropertyApp.context.TablePropertyApp.operationModalRef = value;
            const width = 350;
            store.context.listPagePropertyApp.context.TablePropertyApp.operationModalRef.viewModel.width = width;
        }}>
        <TableOperationProerty onReady={(that) => {
        }}></TableOperationProerty>
    </LegionsProModal>
}